
const connection=require("../app/databases")

class FileService{
    //上传文件信息
    async uploadInfoService(filename,mimetype,size,id){
        const statement=`insert into avatar(filename,mimetype,size,user_id) values(?,?,?,?)`
        const result=await connection.execute(statement,[filename,mimetype,size,id])
        console.log(result)
        return result;
    }
    //展示文件
    async getavatarService(userid){
        const statement=`select * from  avatar where user_id=?`
        const result=await connection.execute(statement,[userid])
        return result[0]
    }
    //将文件地址保存到用户表中
    async uploadAvatarURl(avatarUrl,userid){
        const statement=`update user set avatar_url=? where  id=?`
        const result=await connection.execute(statement,[avatarUrl,userid])
       
        return result;
    }
    //上传多个文件到file表中
    async uploadsPictrue(filename,mimetype,size,momentid){
    
        const statement =`insert into file(filename,mimetype,size,moment_id) values (?,?,?,?)`
        const result=await connection.execute(statement,[filename,mimetype,size,momentid])
        return result[0]       
    }
    //根据图片名字查询动态图片
    async getFileByFileNameService(filename){
        const statement=`select * from file where  filename=?`
        const result=await connection.execute(statement,[filename])
        return result[0]
    }

}
module.exports=new FileService()